//
//  FoncusOnGoodsTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/4.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "FoncusOnGoodsTableViewCell.h"
@class ShodwView;

@implementation ShodwView

-(id)initWithInSuperView:(UIView *)aSuperView{
    if (self = [super initWithInSuperView:aSuperView]) {
//        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];//145
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.44];
        GLGWImageView * noGoodsImageView = [[GLGWImageView alloc] initWithImageName:@"ll" inSuperView:self];
        noGoodsImageView.backgroundColor = kRandomColor;
        [noGoodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(50));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(35)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(26)));
        }];
        //
        GLGWLabel * noGoodsLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor whiteColor] inSuperView:self];
        noGoodsLabel.text = @"缺货中";
        [noGoodsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(noGoodsImageView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(4));
        }];
    }
    return self;
}

@end

@interface FoncusOnGoodsTableViewCell ()
@property (nonatomic,strong)GLGWView * bankgroundView;
@property(nonatomic,strong)GLGWImageView * goodsImageView;
@property(nonatomic,strong)GLGWLabel * stellNameLabel;
@property(nonatomic,strong)GLGWLabel * specLabel;
@property(nonatomic,strong)GLGWLabel * warehouseLabel;
@property(nonatomic,strong)GLGWLabel * piceLabel;
@property(nonatomic,strong)GLGWLabel * foncusPiceLabel;
@property(nonatomic,strong)GLGWLabel * storeNameLabel;
@property(nonatomic,strong)GLGWView * leftView;
@property(nonatomic,assign)CGFloat moveNum;

@property(nonatomic,strong)ShodwView * shodw_View;
@end

@implementation FoncusOnGoodsTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.bankgroundView = [[GLGWView alloc] initWithInSuperView:self];
        self.bankgroundView.backgroundColor = [UIColor whiteColor];
        [self.bankgroundView setViewShadowWidth:3.0 theCornerRadius:3.0];
        [self.bankgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.bottom.equalTo(self.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(5));
        }];
        //
        self.goodsImageView = [[GLGWImageView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(15), kHeightProportion_In_iPhoneTriploid(15), kWidthProportion_In_iPhoneTriploid(82), kHeightProportion_In_iPhoneTriploid(82)) inSuperView:self.bankgroundView];
        self.goodsImageView.backgroundColor = kRandomColor;
        //
        self.stellNameLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self.bankgroundView];
        self.stellNameLabel.text = @"三级螺纹钢 HRB400E 河钢";
        [self.stellNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsImageView.mas_right).offset(kWidthProportion_In_iPhoneTriploid(19));
            make.right.equalTo(self.bankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.bankgroundView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(20));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        }];
        //
        self.specLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.bankgroundView];
        self.specLabel.text = @"φ6*12";
        [self.specLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stellNameLabel);
            make.top.equalTo(self.stellNameLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(7));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        //
        self.warehouseLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.bankgroundView];
        self.warehouseLabel.text = @"北京京南国储库";
        [self.warehouseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.specLabel.mas_right).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.top.equalTo(self.stellNameLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(8));
            make.right.equalTo(self.bankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
        }];
        // 设置优先级
        [self.specLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
        [self.warehouseLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
        //
        self.piceLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.bankgroundView];
        self.piceLabel.text = @"¥3845/吨";
        [self.piceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stellNameLabel);
            make.top.equalTo(self.specLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(8));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        //
        self.foncusPiceLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(10) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.bankgroundView];
        self.foncusPiceLabel.textAlignment = NSTextAlignmentCenter;
        self.foncusPiceLabel.text = @"关注时￥3845/吨";
        self.foncusPiceLabel.layer.cornerRadius = 2.0;
        self.foncusPiceLabel.layer.borderWidth = 1.0;
        self.foncusPiceLabel.layer.borderColor = [UIColor colorWithHexString:@"#EC5353"].CGColor;
        self.foncusPiceLabel.layer.masksToBounds = YES;
        [self.foncusPiceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(7));
            make.top.equalTo(self.stellNameLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(37));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(95)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(18)));
        }];
        //
        GLGWView * lineView = [[GLGWView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(15), kY_With_View(self.goodsImageView, 15), KScreenWidth - kWidthProportion_In_iPhoneTriploid(60), 1.0) inSuperView:self.bankgroundView];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        //
        self.storeNameLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.bankgroundView];
        self.storeNameLabel.text = @"小张店铺";
        [self.storeNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bankgroundView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(lineView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        //
        GLGWButton * pushStoreBut = [[GLGWButton alloc] initWithTitleLableFontType:SYSTEMFONT(12) titleColor:kColor_Rule_Yellow inSuperView:self.bankgroundView];
        pushStoreBut.title = @"进店>";
        [pushStoreBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(lineView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(5));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(40)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(27)));
        }];
        //阴影
        self.shodw_View = [[ShodwView alloc] initWithInSuperView:self.bankgroundView];
        [self.shodw_View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.bankgroundView);
        }];
        //
        self.leftView = [[GLGWView alloc] initWithInSuperView:self];
        [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_left).offset(0);
            make.top.bottom.equalTo(self);
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(30)));
        }];
        GLGWButton * editBut = [[GLGWButton alloc] initInSuperView:self.leftView];
        [editBut setImage:[UIImage imageNamed:@"CellButton"] forState:UIControlStateNormal];
        [editBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.leftView);
            make.left.equalTo(self.leftView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(16)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(16)));
        }];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
    [super setEditing:editing animated:animated];
    if (editing) {
        [self customMultipleChioce];
    }else{
        [self customMultiple];
    }
}

-(void)customMultipleChioce{
    self.moveNum = kWidthProportion_In_iPhoneTriploid(30);
    [self updateMasonry];
    [UIView animateWithDuration:0.5 animations:^{
        [self layoutIfNeeded];
    }];
}
-(void)customMultiple{
    self.moveNum = 0;
    [self updateMasonry];
    [UIView animateWithDuration:0.5 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)updateMasonry{
    [self.bankgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15)+self.moveNum);
        make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(10));
        make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15)+self.moveNum);
        make.bottom.equalTo(self.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(5));
    }];
    [self.leftView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_left).offset(self.moveNum);
        make.top.bottom.equalTo(self);
        make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(30)));
    }];
}
@end
